package com.usian.intercept;

import com.usian.utils.threadlocal.WmThreadLocalUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AdminReferchIntercept implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String newtoken = request.getHeader("newtoken");
        String userId = request.getHeader("userId");
        if (StringUtils.isNotBlank(userId)){
            WmThreadLocalUtils.setUserId(Integer.parseInt(userId));
        }

        if (StringUtils.isNotBlank(newtoken)){
            response.setHeader("REETIME_TONKEN",newtoken);
        }
        return true;
    }
}
